{extend name="default/layout" /}

{block name="css"}
<link href="/static/default/css/user/common.css?v={$static_version}" rel="stylesheet">
{/block}

{block name="content"}
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">

    <div class="grid grid-cols-1 lg:grid-cols-4 gap-8">

        <!-- 侧边栏导航 -->
        {assign name="current" value="favorite" /}
        {include file="default/components/user-sidebar" /}

        <!-- 主要内容区域 -->
        <div class="lg:col-span-3">
            <!-- 页面标题 -->
            <div class="bg-white rounded-t p-4  border-b border-gray-200">
                <div class="flex items-center justify-between">
                    <h1 class="text-xl font-bold text-gray-800">我的收藏</h1>
                    <span class="text-sm text-gray-500">共 {$total} 个商品</span>
                </div>
            </div>

            <!-- 收藏列表 -->
            {if $favorites}
            <div class="bg-white rounded-b  overflow-hidden">
                <div class="divide-y">
                    {volist name="favorites" id="favorite"}
                    <div class="p-4 hover:bg-gray-50 transition-colors" data-goods-id="{$favorite.id}">
                        <div class="flex items-center justify-between">
                            <!-- 左侧商品信息 -->
                            <div class="flex-1 min-w-0">
                                <h3 class="font-medium text-gray-800 mb-2 cursor-pointer hover:text-blue-500 truncate"
                                    onclick="window.location.href='{$favorite.url}'">
                                    {$favorite.name}
                                </h3>
                                <div class="flex items-center gap-4 text-sm text-gray-500">
                                    <span>收藏于 {$favorite.create_time|date='Y-m-d'}</span>
                                    <span class="font-medium text-blue-500">
                                        {if $favorite.price != '0.00'}
                                            {:conf('site_currency_symbol')}{$favorite.price}
                                        {else}
                                            免费
                                        {/if}
                                    </span>
                                </div>
                            </div>

                            <!-- 右侧操作按钮 -->
                            <div class="flex items-center gap-2 ml-4">
                                <button onclick="window.location.href='{$favorite.url}'" target="_blank"
                                    class="px-3 py-1 bg-blue-500 text-white rounded text-sm hover:bg-blue-600 transition-colors">
                                    查看
                                </button>
                                <button onclick="FavoritePage.removeFavorite({$favorite.id})"
                                    class="px-3 py-1 border border-red-300 text-red-600 rounded text-sm hover:bg-red-50 transition-colors">
                                    取消收藏
                                </button>
                            </div>
                        </div>
                    </div>
                    {/volist}
                </div>
            </div>

            <!-- 分页 -->
            {if $total > $per_page}
            <div class="flex justify-center">
                <nav class="flex items-center space-x-2">
                    {if $current_page > 1}
                    <a href="?page={$current_page-1}"
                        class="px-3 py-2 border rounded-sm text-gray-500 hover:text-blue-500 hover:border-blue-500 transition-colors">
                        上一页
                    </a>
                    {/if}

                    {php}
                    $total_pages = ceil($total / $per_page);
                    $start_page = max(1, $current_page - 2);
                    $end_page = min($total_pages, $current_page + 2);
                    {/php}

                    {for start="$start_page" end="$end_page"}
                    {if $i == $current_page}
                    <span class="px-3 py-2 bg-blue-500 text-white rounded-sm">{$i}</span>
                    {else}
                    <a href="?page={$i}"
                        class="px-3 py-2 border rounded-sm text-gray-500 hover:text-blue-500 hover:border-blue-500 transition-colors">
                        {$i}
                    </a>
                    {/if}
                    {/for}

                    {if $current_page < $total_pages} <a href="?page={$current_page+1}"
                        class="px-3 py-2 border rounded-sm text-gray-500 hover:text-blue-500 hover:border-blue-500 transition-colors">
                        下一页
                        </a>
                        {/if}
                </nav>
            </div>
            {/if}

            {else}
            <!-- 无收藏提示 -->
            <div class="bg-white rounded-b p-12  text-center">
                <div class="text-gray-500">
                    <i class="fas fa-heart text-6xl mb-6"></i>
                    <h3 class="text-xl font-medium mb-2">暂无收藏</h3>
                    <p class="mb-6">您还没有收藏任何商品</p>
                    <a href="/"
                        class="inline-block px-6 py-3 bg-blue-500 text-white rounded-sm hover:bg-blue-600 transition-colors">
                        去逛逛
                    </a>
                </div>
            </div>
            {/if}
            <div class="empty-state">
                
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<!-- 引入外部JS文件 -->
<script src="/static/default/js/user/favorite.js?v={$static_version}"></script>
{/block}